﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.SpecialUtils.PicBed.Sina;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SinaImgUpload.SainTool.LocalTool
{
    internal class UploadUtils
    {  /// <summary>
       /// 需要被锁定的常见失效图片大小和尺寸
       /// </summary>
        public static List<WebHelper.BlockImgInfo> BlockImgInfo = new List<WebHelper.BlockImgInfo> {
                new WebHelper.BlockImgInfo{  FileSize=8844, ImgHeight=480, ImgWidth=360},
                new WebHelper.BlockImgInfo{  FileSize=8308, ImgHeight=360, ImgWidth=480},
                  new WebHelper.BlockImgInfo{  FileSize=8271, ImgHeight=360, ImgWidth=480},
                  new WebHelper.BlockImgInfo{  FileSize=7092, ImgHeight=360, ImgWidth=360}
            };

        /// <summary>
        /// 上传一个文件夹 里的图片
        /// </summary>
        /// <param name="FloderPath"></param>
        /// <returns></returns>
        public static List<string> UploadFloder(string FloderPath)
        {
            List<string> TempList = new List<string>();
            List<string> Filelist = GetImgFileList(FloderPath);
            int UplodadCount = 0;
            foreach (string line in Filelist)
            {
                Console.WriteLine("上传文件{0}，总数量{1},已上传{2}", FileNameHelper.GetFileName(line), Filelist.Count, UplodadCount++);
                if (line != "")
                    TempList.Add(SinaImgUploadTool.UploadFile(line));
            }
            return TempList;
        }

        /// <summary>
        ///  上传一个文件夹 里的图片,需要文件大小
        /// </summary>
        /// <param name="FloderPath"></param>
        /// <param name="Fileise"></param>
        /// <returns></returns>
        public static List<string> UploadFloder(string FloderPath, int Fileise)
        {
            List<string> TempList = new List<string>();
            List<string> Filelist = GetImgFileList(FloderPath);
            int UplodadCount = 0;
            foreach (string line in Filelist)
            {
                if (line != "")
                {
                    Console.WriteLine("上传文件{0}，总数量{1},已上传{2}", FileNameHelper.GetFileName(line), Filelist.Count, UplodadCount++);
                    if (line != "")
                        TempList.Add(SinaImgUploadTool.UploadFile(line));
                }
            }
            return TempList;
        }

        /// <summary>
        /// 获取文件夹下所有图片
        /// </summary>
        /// <param name="FloderPath"></param>
        /// <returns></returns>
        private static List<string> GetImgFileList(string FloderPath)
        {
            return Directory.GetFiles(FloderPath, "*.*",
                    SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".jpeg") || s.EndsWith(".gif")
                    || s.EndsWith(".ico")).ToList();
        }
    }
}